package com.upc.feedish;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.upc.feedish.utils.DataBaseController;
import com.upc.feedish.utils.MyTools;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class AdviceActivity extends AppCompatActivity {
    Uri imageUri;
    String picBase64;
    Handler handler;
    String name;
    ImageView imageView;
    TextView tv_name;
    TextView tv_appetite;
    TextView tv_temperature;
    DataBaseController dataBaseController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advice);

        dataBaseController=new DataBaseController();
        imageView=(ImageView)findViewById(R.id.imageView);
        tv_name=(TextView)findViewById(R.id.name);
        tv_appetite=findViewById(R.id.appetite);
        tv_temperature=findViewById(R.id.temperature);


        handler = new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                HashMap<String,Object> map= (HashMap<String, Object>) msg.obj;
                tv_name.setText("种类："+map.get("name"));
                tv_appetite.setText("建议喂食量："+map.get("appetite")+"单位");
                tv_temperature.setText("适宜温度："+map.get("temperature")+"℃");
            };
        };
    }
    public void openLocalPic(View v){
        //打开本地相册
        Intent i = new Intent(
                Intent.ACTION_PICK,
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        //设定结果返回
        startActivityForResult(i, 2);
    }
    public void openCamera(View v){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // 关键：新建相机的 Intent
        startActivityForResult(intent, 1); // 加载相机 Activity
    }


    @Override
    //重写onActivityResult(int,int,Intent)获取系统相机的返回数据
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}